﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace manganelos
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private async void button1_Click(object sender, EventArgs e)
        {
            if (!System.IO.Directory.Exists(textBox2.Text))
            {
                Print("Erro: 文件夹路径不存在，请检查路径");
                return;
            }
            Print("-------------------Start--------------------");
            ManganelosTools manganelos = new ManganelosTools(textBox1.Text);
            manganelos.printAction = Print;
            string info = manganelos.SetManganelos();
            bool key = manganelos.ChackNumber(info);
            if (!key) return;
            await Task.Run(() => { manganelos.DownForAllChapter(textBox2.Text); });
            Print("--------------------End---------------------");

        }

        void Print(string str)
        {
            if (!string.IsNullOrWhiteSpace(str))
            {
                this.Invoke(new Action(()=> 
                {
                    richTextBox1.AppendText("\n" + str);
                }));
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            richTextBox1.ScrollToCaret();
        }
    }
}
